package com.mxf.miaosha.controller;

import com.mxf.miaosha.VO.LoginVO;
import com.mxf.miaosha.result.CodeMsg;
import com.mxf.miaosha.result.Result;
import com.mxf.miaosha.service.MiaoshaUserService;
import com.mxf.miaosha.util.ValidatorUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * 登录
 */
@Controller
@RequestMapping("/login/")
public class LoginController {

    private static Logger logger = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    private MiaoshaUserService miaoshaUserService;

    @RequestMapping("to_login")
    public String to_login(){
        return "login";
    }

    @RequestMapping("do_login")
    @ResponseBody
    public Result<Boolean> do_login(HttpServletResponse response, @Valid LoginVO loginVO) {
        logger.info(loginVO.toString());
        miaoshaUserService.login(response, loginVO);
        return Result.success(true);
    }
}
